package com.tron.dobest.dynamicdatasource;

import com.tron.dobest.mybatisplus.entity.User;
import com.tron.dobest.mybatisplus.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.util.List;

/**
 * 描述：
 *
 * @author TRON
 * @since 2020-04-20
 */
@RestController
@Slf4j
public class TronDataSourceTestController {

    @Autowired
    DataSource dataSource;

    @Autowired
    DynamicDataSourceProperties dynamicDataSourceProperties;

    @Autowired
    UserService userService;

    @GetMapping("/getDataSource")
    public Object getDataSource() {
        log.info(dataSource.toString());
        return dynamicDataSourceProperties;
    }

    @GetMapping("/getUserList")
    public Object getUser() {
        List<User> list = userService.list();
//        System.out.println(1/0);
        return list;
    }

    @GetMapping("/addUser")
    public Object addUser() {
        User user = new User();
        user.setName("我是中文值");
        user.setUserName("我也是中文值");
        userService.save(user);
        return userService.getById(user.getId());
    }


}
